#INCLUDE "rwmake.ch"
#INCLUDE "topconn.ch"

/*
Rotina : FF0029
Respons. Geovani
Data   : 01/12/2011
Cliente: FIBRAFORT
*/

USER FUNCTION FF0029()

	nQtdEtiq:= 0
	cCodIni := space(15)
	cCodFim := space(15)
		
	@ 0,0 TO 270,400 DIALOG oDlg TITLE "Impressao Etiquetas ALMOXARIFADO"
 	@ 008,010 SAY "Produto de :"  SIZE 100,20     
	@ 008,050 GET cCodIni  F3 "SB1" PICTURE "@E" SIZE 50,10 
 	@ 025,010 SAY "Produto ate:"  SIZE 100,20     
	@ 025,050 GET cCodFim  F3 "SB1" PICTURE "@E" SIZE 50,10 VALID fCodf()
 	@ 059,010 SAY "Qtde Etiq. :"  SIZE 100,20     
	@ 059,50 GET nQtdEtiq PICTURE "999" SIZE 10,10 	  
	@ 115,15 BMPBUTTON TYPE 1 ACTION fFF0029(nQtdEtiq,cCodIni,cCodFim)
	@ 115,45 BMPBUTTON TYPE 2 ACTION close(oDlg)	
   	ACTIVATE DIALOG oDlg CENTERED   	         
return        

Static Function fCodf
	if cCodFim < cCodIni
		Alert("Produto final invalido. Verifique !!!")
		Return .f.
	endif                                            
Return .t.

STATIC Function fFF0029(nQtdEtiq,cCodIni,cCodFim)  //IMPRIMI ETIQUETA 

	nHeight    := 10
	lBold      := .T.
	lUnderLine := .F.
	lPrint     := .F.    

	oFont      := TFont():New( "Arial",,nHeight,,lBold,,,,,lUnderLine ) 
	oFont2     := TFont():New( "Arial",,60,,.T.,,,,,lUnderLine )
	oFont3	   := TFont():New("Courier New",,nHeight,,.T.,,,,,lUnderLine )
	oFont4     := TFont():New( "Arial",,35,,.T.,,,,,lUnderLine )		 
	oFont12    := TFont():New( "Arial",,12,,.T.,,,,,lUnderLine )			
	oFont10    := TFont():New( "Arial",,10,,.T.,,,,,lUnderLine )	
	oFont7     := TFont():New( "Arial",,07,,.T.,,,,,lUnderLine )
	oFont8     := TFont():New( "Arial",,08,,.T.,,,,,lUnderLine )

	cQuery := ""
	cQuery += "SELECT B1_COD, B1_DESC, B1_CODBAR, B1_UM, B1_TIPO, B1_DESC2, B1_LOCPAD "
	cQuery += "FROM "+RetSqlName("SB1")+" (NOLOCK) "
	cQuery += "WHERE D_E_L_E_T_ = ' ' AND B1_FILIAL = '"+xFilial("SB1")+"' "
	cQuery += " AND B1_COD BETWEEN '"+cCodINI+"' and '"+cCodFim+"' "
	cQuery += " AND B1_MSBLQL NOT IN ('1') "
		cQuery += "ORDER BY B1_DESC "
	If (Select("T0") <> 0)
		dbSelectArea("T0")
		dbCloseArea()
	Endif   
	cQuery := ChangeQuery(cQuery)
	TCQuery cQuery NEW ALIAS "T0"

	t0->(dbgotop())
	While !t0->(eof()) 
		
		cCodBarra := Alltrim(t0->b1_codbar)
		cDescr1   := Alltrim(Substr(t0->b1_desc,1,40))
		cDescr2   := Alltrim(Substr(t0->b1_desc,41,20))    
        cCodigo   := Alltrim(t0->b1_cod)
        cUM       := Alltrim(t0->b1_UM) 
        cTipo     := Alltrim(t0->b1_tipo)
		cLocal    := Alltrim(t0->b1_locpad)
		        
		For i := 1 to nQtdEtiq         
			oPrn := TMSPrinter():New()
			MSCBPRINTER(" "," ",NIL,20)                
			oPrn:StartPage()  // 0,75                            0.2    7.0
    		msBar("CODE128",0.75,0.50,cCodBarra,oPrn,NIL,NIL,NIL,0.05,0.8,nil,oFont7,"C",lPrint,1,1)
 			//oPrn:Say(210, 070,cCodBarra         ,oFont7,10)            
  			oPrn:Say(180, 045,"Cod: "+cCodigo+space(02)+"Tp: "+cTipo+space(02)+"UM: "+cUM+Space(2)+"Arm: "+space(02)+Alltrim(cLocal),oFont8,10)      
			oPrn:Say(220, 045,Alltrim(cDescr1),oFont8,10)
  			//IF !EMPTY(cDescr2)
  				//oPrn:Say(350, 070,Alltrim(cDescr2),oFont8,10) 
	  			//oPrn:Say(400, 050,"Arm: "+Alltrim(cLocal),oFont8,10) 
  			//ELSE
	  			//oPrn:Say(360, 050,"Arm: "+Alltrim(cLocal),oFont8,10) 
			//ENDIF  			 	
			oPrn:EndPage()      
			oPrn:Print()
			SetPgEject(.F.)
			MS_Flush()        
		Next
		t0->(dbskip())
	End
	If (Select("T0") <> 0)
			dbSelectArea("T0")
			dbCloseArea()
	Endif   
	close(oDlg)
Return()                                    
                             